use std::fmt::{Display, Formatter};

fn main() {
    let people = People {
        name: "123".to_string(),
        age: 18,
    };
    // sport(&people);

    let a = test(&people, &people);
}

struct People {
    name: String,
    age: u32,
}

//方法入参为trait
//单继承
fn say_hello<T: Behavior>(item: &T) {
    item.say_name();
}

fn pro_sport(item: &impl Sport) {
    item.work();
}

// 多继承
fn sport<T: Behavior + Sport>(item: &T) {
    let a = item.work();
    println!("多继承方法中执行work:{}", a)
}

fn test<T, U>(t: &T, u: &U) -> String where T: Behavior, U: Sport {
    t.say_age();
    u.work();
    "success".to_string()
}

trait Behavior {
    //抽象方法，必须实现
    fn say_name(&self);

    //默认实现，可重写
    fn say_age(&self) {
        println!("今年18岁:{}", 18)
    }
}

trait Sport {
    fn work(&self) -> String;
    fn run(&self);
}

impl Behavior for People {
    fn say_name(&self) {
        println!("My name is {}", self.name)
    }
}

impl Sport for People {
    fn work(&self) -> String {
        println!("{} 在走路", self.name);
        "work".to_string()
    }

    fn run(&self) {
        println!("{} 在跑步", self.name)
    }
}

